//
// C++ Implementation: MainWindow
//
// Description: The main window of the program
//
// Author: Burkhard Lehner <Burkhard.Lehner@googlemail.com>, (C) 2006

#include "MainWindow.h"
#include <qlayout.h>       // for QVBoxLayout
#include <qpushbutton.h>   // for QPushButton
#include <qcursor.h>       // for QCursor
#include <qapplication.h>  // for qApp
#include <qstatusbar.h>    // for QStatusBar
//Added by qt3to4:
#include <QVBoxLayout>

MainWindow::MainWindow (QWidget *parent, const char *name)
    //: MainWindowBase (parent, name)
{
    ui.setupUi(this);
    // create the GL widget to show the scene
    glbox = new GLBox (centralWidget(), 0L);

    // the layout object is responsible for controling the sizes of the two widgets "glbox" and "bottomFrame".
    QVBoxLayout *centralLayout = new QVBoxLayout (ui.widget/*, 10*/);

    // we add the glbox first, so it will cover the top part of the window
    // it gets a stretch factor of 1, so it takes all the space it can get
    centralLayout->addWidget (glbox, 1);
    // the bottomFrame is added after that, so it is placed in the bottom part of the window
    // it gets a stretch factor of 0, so it takes only the height it absolutly needs,
    // and leaves the rest for the glbox widget
    centralLayout->addWidget (ui.bottomFrame, 0);

    // connect the signals of all subwidgets to the appropriate slots
    connect (ui.selectButton, SIGNAL (clicked()), this, SLOT (switchToSelect()));
    connect (ui.moveButton, SIGNAL (clicked()), this, SLOT (switchToMove()));
   // connect (glbox, SIGNAL (objectSelected(RenderObject*)), this, SLOT (setSelectedObject(RenderObject*)));

    // currently no object of the scene is selected
    //selectedObject = 0L;

    // initially we start in move mode
    switchToMove();
}

GLBox *MainWindow::getGLBox ()
{
    return glbox;
}

void MainWindow::switchToMove()
{
    glbox->setMovingMode();
    ui.moveButton->setDown (true);
    ui.selectButton->setDown (false);
    glbox->setCursor (QCursor (Qt::PointingHandCursor));
}

void MainWindow::switchToSelect()
{
    glbox->setPickingMode();
    ui.moveButton->setDown (false);
    ui.selectButton->setDown (true);
    glbox->setCursor (QCursor (Qt::ArrowCursor));
}

/*
void MainWindow::setSelectedObject(RenderObject *o)
{
    selectedObject = o;
    if (o == 0L)
    {
        statusBar()->showMessage ("No object selected", 5000);
    }
    else
    {
	statusBar()->showMessage ("Object selected", 5000);
    }
}
*/

void MainWindow::fileExit()
{
    qApp->quit();
}
